<template>
	<view class="container">
		<TopBtn :title="'预览处方'"></TopBtn>
		<view class="currency_card jjBox" v-if="data.auditStatus==2">
			<view class="jjtitle flex-center">
				<image src="@/static/ConsultationRoom/del.png" mode="aspectFill"></image> 拒绝原因
			</view>
			<view class="">
				{{data.auditReason}}
			</view>
		</view>
		<view class="card">
			<view class="title flex-sp-center">
				{{data.hospitalName}}
				<view class="time">
					<uni-dateformat :date="data.createTime" format="yyyy-MM-dd hh:mm"></uni-dateformat>
				</view>
			</view>
			<image class="ytg" v-if="data.auditStatus==1" src="@/static/ConsultationRoom/ytg.png" mode=""></image>
			<view class="info">
				<view class="w50">
					姓名：{{data.patientName}}
				</view>
				<view class="w50">
					性别：{{data.patientSex==1?'男':'女'}}
				</view>
				<view class="w50" v-if="data.height">
					身高：{{data.height}}cm
				</view>
				<view class="w50" v-if="data.weight">
					体重：{{data.weight}}kg
				</view>
				<view class="w50" v-if="data.departName">
					科室：{{data.departName}}
				</view>
				<view class="w50">
					年龄：{{data.patientAge}}岁
				</view>
			</view>
		</view>
		<view class="card">
			<view class="title">
				诊断结果
			</view>
			<view class="info">
				{{data.diagnosis}}
			</view>
		</view>
		<view class="card">
			<view class="title">
				rp 中药饮片
			</view>
			<view class="info">
				<view class="w50" v-for="n in showdrugName">
					{{n.name}}{{n.dosage}} <text v-if="n.DecoctionMethod">({{n.DecoctionMethod}})</text>
				</view>
				<view class="row">
					<text>用法：</text>
					共{{showapply.dose}}剂，{{showapply.operationMethod}}，{{showapply.dosageNum}}，{{showapply.usageCount}}，{{showapply.perUse}}
				</view>
				<view class="row" v-if="data.machining">
					<text>加工：</text>
					{{data.machining}}
				</view>
				<view class="row" v-if="data.medicalAdvice">
					<text>医嘱：</text>
					{{data.medicalAdvice}}
				</view>
			</view>
		</view>
		<view class="card">
			<view class="title">
				备注
			</view>
			<view class="info">
				1、处方有效期为3天; <br />
				2、支持凭本处方到线下药店购药或将本处方上传至其他网上购药平台(如京东、阿里等)找医生抄方后购药;<br />
				3、如需医保报销，您需凭本处方到附近线下实体医院抄方购药<br />
			</view>
		</view>
		<view class="kong">

		</view>
		<view class="btnBox flex-sp-center" v-if="data.auditStatus==0">
			<view class="updata flex-center-center" @click="openPup()">
				驳回
			</view>
			<view class="add flex-center-center" @click="sub(1)">
				审核
			</view>
		</view>
		<uni-popup ref="popup" type="bottom">
			<view class="pupbox">
				<view class="title">
					<view class="close" @click="closePup()">
						取消
					</view>
					驳回原因
					<view class="add" @click="sub(2)">
						确认
					</view>
				</view>
				<view class="">
					<textArea v-model="rejectReason" :inputNane="rejectReason" :maxNum="50"></textArea>
				</view>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	import {
		pharmacistGetPrescriptionInfo,
		createPrescriptionInfo,
		updatePrescriptionInfo
	} from '@/api/ConsultationRoom'
	import {
		auditPharmacistInfo,
	} from '@/api/user'
	export default {
		data() {
			return {
				data: {},
				id: "",
				showdrugName: {},
				showapply: {},
				type: 1,
				butShow: true,
				rejectReason: ""
			};
		},
		onLoad(e) {
			let that = this
			if (e.id) {
				this.id = e.id
				this.pharmacistGetPrescriptionInfo()
			}
			if (e.updata == 0) {
				this.butShow = false
			}
			if (e.type == 2) {
				uni.getStorage({
					key: 'paramsData',
					success: function(res) {
						if (res.data) {
							that.data = JSON.parse(res.data);
							that.showdrugName = JSON.parse(that.data.drugName)
							that.showapply = JSON.parse(that.data.apply)
							console.log(that.data)
						}
					}
				});
			}
		},
		methods: {
			openPup(e, id) {
				this.$refs.popup.open('bottom')
				this.rejectReason = ""
			},
			sub(e) {
				if (e == 2 && !this.rejectReason) {
					uni.showToast({
						title: '请填写驳回原因',
						duration: 1000,
						icon: 'none',
					})
				}

				uni.showLoading({
					title: '加载中',
					mask: true
				})
				auditPharmacistInfo({
					id: this.id,
					auditStatus: e,
					auditReason: this.rejectReason
				}).then(res => {

					uni.showToast({
						title: '操作成功',
						duration: 200,
						icon: 'none',
					})
					setTimeout(() => {
						uni.hideLoading()
						uni.$emit('show', true)
						uni.navigateBack({
							delta: 2, //返回层数，2则上上页
						})
					}, 200); // 3000毫秒后执行
				})

			},
			pharmacistGetPrescriptionInfo() {
				pharmacistGetPrescriptionInfo({
					id: this.id
				}).then(res => {
					this.data = res.data
					this.showdrugName = JSON.parse(res.data.drugName)
					this.showapply = JSON.parse(res.data.apply)
					console.log(this.showdrugName)
					console.log(this.showapply)
				})
			},
		}
	}
</script>

<style lang="less" scoped>
	.jjBox {
		width: 100%;
		border-radius: 0;
		margin: 30rpx auto;
		font-weight: 500;
		font-size: 28rpx;
		color: #333333;

		.jjtitle {
			margin-bottom: 15rpx;
			font-weight: bold;
			font-size: 32rpx;
			color: #333333;

			image {
				width: 33rpx;
				height: 33rpx;
			}
		}
	}

	.btnBox {
		position: fixed;
		width: 750rpx;
		bottom: 0;
		height: 162rpx;
		background: #FFFFFF;
		padding: 0 50rpx;
		box-sizing: border-box;

		.updata {
			width: 218rpx;
			height: 100rpx;
			background: #FFFFFF;
			border-radius: 50rpx;
			font-weight: 500;
			font-size: 28rpx;
			color: #3B6CFE;
			border: 1px solid #3B6CFE;
		}

		.add {
			width: 364rpx;
			height: 100rpx;
			background: #3B6CFE;
			border-radius: 50rpx;
			font-weight: 500;
			font-size: 28rpx;
			color: #FFFFFF;
		}
	}

	.pupbox {
		width: 750rpx;
		height: 522rpx;
		background: #ffffff;
		border-radius: 50rpx 50rpx 0rpx 0rpx;
		padding: 30rpx 50rpx;
		box-sizing: border-box;
		background-size: 100% 100%;

		.title {
			font-size: 36rpx;
			font-weight: bold;
			color: #333333;
			position: relative;
			display: flex;
			justify-content: space-between;
			align-items: center;

			.add {
				font-weight: 500;
				font-size: 28rpx;
				color: #3E6EFE
			}

			.close {
				font-weight: 500;
				font-size: 28rpx;
				color: #999999;
			}

		}

		.messageList {
			margin-top: 1em;

			margin-top: 1em;

			.scroll-view_H {
				white-space: nowrap;
				width: 100%;
			}

			.messageinfo {
				display: inline-block;
				width: 287rpx;
				height: 220rpx;
				border: 2px solid #eeeeee;
				border-radius: 15rpx;
				margin-right: 25rpx;
				padding: 20rpx;
				box-sizing: border-box;
				font-size: 26rpx;
				font-weight: 500;
				color: #999999;
				vertical-align: top;
			}

			.text {
				height: 100%;
				display: flex;
				align-items: center;
				white-space: wrap;
				white-space: pre-wrap;
				/* css-3 */
				white-space: -moz-pre-wrap;
				/* Mozilla, since 1999 */
				white-space: -pre-wrap;
				/* Opera 4-6 */
				white-space: -o-pre-wrap;
				/* Opera 7 */
				word-wrap: break-word;
				/* Internet Explorer 5.5+ */
			}

			.act {
				border: 4rpx solid #aa75fa;
				color: #7e67fd;
			}
		}

		// 多行文本输入框
		/deep/.uni-easyinput__content {
			border: none;
		}

		// 多行文本输入框
		/deep/.is-textarea {
			background-color: #f9f9f9 !important;
			margin: 23rpx 0 40rpx;
		}

		/deep/.is-input-border {
			border-radius: 20rpx;
		}

		/deep/.uni-easyinput__placeholder-class {
			font-size: 28rpx;
		}
	}

	.card {
		margin-top: 30rpx;
		width: 750rpx;
		min-height: 122rpx;
		background: #FFFFFF;
		padding: 0 30rpx 30rpx;
		box-sizing: border-box;
		position: relative;

		.ytg {
			position: absolute;
			top: 24rpx;
			right: 35rpx;
			width: 172rpx;
			height: 171rpx;
		}

		.title {
			height: 95rpx;
			line-height: 95rpx;
			font-weight: bold;
			font-size: 34rpx;
			color: #333333;
			border-bottom: 1px solid #EEEEEE;

			.time {
				font-weight: 500;
				font-size: 24rpx;
				color: #999999;
			}
		}

		.info {
			padding-top: 30rpx;
			font-weight: 500;
			font-size: 28rpx;
			color: #333333;
			display: flex;
			flex-wrap: wrap;

			.w50 {
				width: 50%;
				margin-bottom: 20rpx;
			}

			.row {
				margin-top: 20rpx;
				width: 100%;
				display: flex;

				text {
					width: 120rpx;
				}
			}
		}
	}
</style>